package com.hyk.commonLib.common.utils.dataBinding.bindingAdapter;

import android.view.View;

import androidx.databinding.BindingAdapter;

import com.hyk.commonLib.common.utils.ScreenUtils;

/**
 * Created by 贺玉琨 on 2020/7/28.
 */
public class PaddingAdapter {

    @BindingAdapter("paddingHorizontal")
    public static void setHorizontalPadding(View view, float horizontalPadding) {
        int horizontalPaddingPx = ScreenUtils.dp2px(horizontalPadding);
        view.setPadding(horizontalPaddingPx, view.getPaddingTop(), horizontalPaddingPx, view.getPaddingBottom());
    }

    @BindingAdapter("paddingVertical")
    public static void setVerticalPadding(View view, float verticalPadding) {
        int verticalPaddingPx = ScreenUtils.dp2px(verticalPadding);
        view.setPadding(view.getPaddingLeft(), verticalPaddingPx, view.getPaddingRight(), verticalPaddingPx);
    }

    @BindingAdapter("paddingLeft")
    public static void setLeftPadding(View view, float leftPadding) {
        view.setPadding(ScreenUtils.dp2px(leftPadding), view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
    }

    @BindingAdapter("paddingTop")
    public static void setTopPadding(View view, float topPadding) {
        view.setPadding(view.getPaddingLeft(), ScreenUtils.dp2px(topPadding), view.getPaddingRight(), view.getPaddingBottom());
    }

    @BindingAdapter("paddingRight")
    public static void setRightPadding(View view, float rightPadding) {
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), ScreenUtils.dp2px(rightPadding), view.getPaddingBottom());
    }

    @BindingAdapter("paddingBottom")
    public static void setBottomPadding(View view, float bottomPadding) {
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), ScreenUtils.dp2px(bottomPadding));
    }

    @BindingAdapter("paddingLeftPx")
    public static void setLeftPaddingPx(View view, int leftPadding) {
        view.setPadding(leftPadding, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
    }

    @BindingAdapter("paddingTopPx")
    public static void setTopPaddingPx(View view, int topPadding) {
        view.setPadding(view.getPaddingLeft(), topPadding, view.getPaddingRight(), view.getPaddingBottom());
    }

    @BindingAdapter("paddingRightPx")
    public static void setRightPaddingPx(View view, int rightPadding) {
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), rightPadding, view.getPaddingBottom());
    }

    @BindingAdapter("paddingBottomPx")
    public static void setBottomPaddingPx(View view, int bottomPadding) {
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), bottomPadding);
    }
}
